package com.aclyyx.mi.display.listener;

import com.aclyyx.mi.display.FirstActivity;
import com.aclyyx.mi.display.Param;
import com.aclyyx.mi.display.R;
import com.aclyyx.mi.display.remote.client.StartForRemote;

import android.view.View;
import android.widget.Toast;

public class ClientStart implements View.OnClickListener {
	
	public FirstActivity a;
	
	public ClientStart(FirstActivity context) {
		this.a = context;
	}

	@Override
	public void onClick(View v) {
		
		if (a.clientStarted) {
			if (a.timer != null) {
				a.timer.cancel();
				a.timer = null;
			}
			a.clientStarted = false;
			a.btnStart2.setText(R.string.b_start2);
		} else {
			a.clientStarted = true;
			a.btnStart2.setText(R.string.b_start2_);
			try {
				a.param			= new Param();
				a.param.run_type= Param.RUN_TYPE_CLIENT;
				a.param.isOk	= false;
				a.param.ip		= a.editIP.getText().toString();
				a.param.port	= a.editPort.getText().toString();
				
				StartForRemote sfr = new StartForRemote(a);
				sfr.start(a.param);
//				Toast.makeText(a, "started", Toast.LENGTH_SHORT).show();
				
//				Intent i = new Intent(FirstActivity.this, MiActivity.class);
//				i.putExtra("param", param);
//				startActivity(i);
			
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		
		
	}

}
